package com.api.gbhg.daiyanlu.action;

import com.api.gbhg.daiyanlu.Dao.PrintCopyActionDao;
import com.api.gbhg.daiyanlu.DataPrintCopyUtil.DataPrintCopy;
import com.api.gbhg.lbj.dao.GeneralProjectDao;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import com.api.gbhg.zengping.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;


/**
 * 15 海关养老保险缴费经费入库
 */
public class EndowmentPut implements Action {
    private static final Logger log= LoggerFactory.getLogger("gbhg");
    @Override
    public String execute(RequestInfo requestInfo) {
        log.info("------------------海关养老保险缴费经费开始入库--------------------------");
        PropertyManagementCostDao p=new PropertyManagementCostDao();
        PrintCopyActionDao dao=new PrintCopyActionDao();
        //RecordSet rs= DataPrintCopy.getRs(requestInfo.getRequestid(),"uf_hgylbxjfjfxqb");
        RecordSet rs = dao.getEducationFundStorage(requestInfo.getRequestid());
        Map<String, String> map = new HashMap<>();
        String requestid = requestInfo.getRequestid();
        RecordSet recordSet = GeneralProjectDao.deleteWorkflowByid(requestid);
        recordSet.next();
        boolean b = true;

        while(rs.next()) {
            map.put("requestId", requestInfo.getRequestid());
            map.put("sbdw", rs.getStringNoTrim("sbdw"));
            map.put("xmmc", rs.getStringNoTrim("xmmin"));
            map.put("lcbj", rs.getStringNoTrim("lcbj"));
            map.put("lcjlid", rs.getStringNoTrim("lcjlsqjlid"));
            map.put("bmzcjjfl", rs.getStringNoTrim("bmyszcjjfl"));
            map.put("zfjjfl", rs.getStringNoTrim("dyzfjjfl"));
            map.put("nd", rs.getStringNoTrim("ysnd"));
            map.put("ze", rs.getStringNoTrim("hjwy"));
            String syed = "0.00";
            if (rs.getStringNoTrim("hjwy").equals("")) {
                map.put("ze", "0.00");
                syed = "0.00";
            } else {
                syed = rs.getStringNoTrim("hjwy");
            }

            map.put("syed", syed);
            map.put("dj", "0.00");
            map.put("modedatamodifier", rs.getStringNoTrim("jbr"));
            map.put("gkdw", rs.getStringNoTrim("gkdw"));
            map.put("sydw", rs.getStringNoTrim("sydw"));
            map.put("modedatamodifydatetime", DateUtil.getNowDate());
            boolean resV = p.insertBudgeLines(map);
            if (!resV) {
                b = false;
            }
        }
        if (!b) {
            requestInfo.getRequestManager().setMessagecontent("海关养老保险缴费经费入库失败");
            requestInfo.getRequestManager().setMessageid("");
            log.info("同步流程海关养老保险缴费经费数据到入库表失败！");
            return "0";
        } else {
            return "1";
        }
    }
}
